{% extends "base.html" %}

{% block title %}
    我的博客
{% endblock %}

{% block content %}
    <h1>我的博客</h1>
    {% if tag %}
        <h2>{{ tag.name }}下的所有文章</h2>
    {% endif %}
    {% for post in posts %}
        <h2>
            <a href="{{ post.get_absolute_url }}">
                {{ post.title }}
            </a>

        </h2>

        <p class="tags">
            标签：
            {% for tag in post.tags.all %}
                <a href="{% url 'blog:post_list_by_tag' tag.slug %}">{{ tag.name }}</a>
                {% if not forloop.last %},{% endif %}
            {% endfor %}
        </p>
        <p class="date">
            Published {{ post.publish }} by {{ post.author }}
        </p>
{#        truncatechars 用来截断指定数量的文字#}
{#        linebreaks 将结果带上html换行#}
        {{ post.body|truncatechars:30|linebreaks }}
        {% load blog_tags %}
        {{ count|add_num:2 }}
    {% endfor %}
{#    由视图传递给列表页的Page对象的名称叫做posts 通过with重新指定变量名称以让分页模板也能正确接收到该对象#}
{#    {% include 'pagination.html' with page=page_obj %}#}
    {% include 'pagination.html' with page=posts %}
{% endblock %}